package com.legal.aid.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.legal.aid.common.annotation.Log;
import com.legal.aid.common.core.controller.BaseController;
import com.legal.aid.common.core.domain.AjaxResult;
import com.legal.aid.common.enums.BusinessType;
import com.legal.aid.system.domain.Advertisement;
import com.legal.aid.system.service.IAdvertisementService;
import com.legal.aid.common.utils.poi.ExcelUtil;
import com.legal.aid.common.core.page.TableDataInfo;

/**
 * 轮播广告管理Controller
 * 
 * @author ruoyi
 * @date 2025-05-28
 */
@RestController
@RequestMapping("/system/ad")
public class AdvertisementController extends BaseController
{
    @Autowired
    private IAdvertisementService advertisementService;

    /**
     * 查询轮播广告管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:ad:list')")
    @GetMapping("/list")
    public TableDataInfo list(Advertisement advertisement)
    {
        startPage();
        List<Advertisement> list = advertisementService.selectAdvertisementList(advertisement);
        return getDataTable(list);
    }

    /**
     * 导出轮播广告管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:ad:export')")
    @Log(title = "轮播广告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Advertisement advertisement)
    {
        List<Advertisement> list = advertisementService.selectAdvertisementList(advertisement);
        ExcelUtil<Advertisement> util = new ExcelUtil<Advertisement>(Advertisement.class);
        util.exportExcel(response, list, "轮播广告管理数据");
    }

    /**
     * 获取轮播广告管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ad:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(advertisementService.selectAdvertisementById(id));
    }

    /**
     * 新增轮播广告管理
     */
    @PreAuthorize("@ss.hasPermi('system:ad:add')")
    @Log(title = "轮播广告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Advertisement advertisement)
    {
        return toAjax(advertisementService.insertAdvertisement(advertisement));
    }

    /**
     * 修改轮播广告管理
     */
    @PreAuthorize("@ss.hasPermi('system:ad:edit')")
    @Log(title = "轮播广告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Advertisement advertisement)
    {
        return toAjax(advertisementService.updateAdvertisement(advertisement));
    }

    /**
     * 删除轮播广告管理
     */
    @PreAuthorize("@ss.hasPermi('system:ad:remove')")
    @Log(title = "轮播广告管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(advertisementService.deleteAdvertisementByIds(ids));
    }
}
